package com.wtf.dsp.admin.util;

import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * ClassName: MapperConstant
 * Description: 组装Mapper.xml的常量类
 * date: 2023/7/11 10:06
 *
 * @author linhuanyou
 * @version 1.0
 */
public class MapperXmlUtil {
    public static final String MAPPER_DOCUMENT_DOCTYPE_AND_HEAD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
             "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">\n";

    public static final String MAPPER_NODE_NAMESPACE = "${nsId.ds.mnsId}";

    public static final String MAPPER_NODE_PREFIX = "<mapper namespace=\"${nsId.ds.mnsId}\">\n";

    public static final String MAPPER_NODE_SUFFIX = "</mapper>";

    public static String mapperXmlStr(String namespace, List<String>  sqlXmlStrs){
        StringBuilder mapperNamespace = new StringBuilder(MAPPER_DOCUMENT_DOCTYPE_AND_HEAD);
        mapperNamespace.append(MAPPER_NODE_PREFIX.replace(MAPPER_NODE_NAMESPACE,namespace));
        for (String sqlXmlStr : sqlXmlStrs) {
           if(StringUtils.isBlank(sqlXmlStr)){
               continue;
           }
            mapperNamespace.append(sqlXmlStr).append("\n");
        }
        mapperNamespace.append(MAPPER_NODE_SUFFIX);
        return mapperNamespace.toString();
    }
}
